#include<bits/stdc++.h>
using namespace std;
const int MAXN=1010,MAXM=10010;
int n,m,cnt,head[MAXN];
bool vis[MAXN];
struct edge
{
	int v,next,x,y;
}e[MAXM*2];
struct point
{
	int x,y;
}p[MAXN];
void addedge(int u,int v,int x,int y)
{
	e[++cnt]=(edge){v,head[u],x,y};
	head[u]=cnt;
}
int gcd(int a,int b)
{
	return b?gcd(b,a%b):a;
}
bool dfs(int u)
{
	vis[u]=true;
	for(int i=head[u];i;i=e[i].next)
	{
		int v=e[i].v,x=p[u].x*e[i].x,y=p[u].y*e[i].y,t;
		t=gcd((int)abs(x),(int)abs(y));
		x/=t;y/=t;
		if(vis[v])
		{
			if(x==p[v].x&&y==p[v].y)continue;
			return false;
		}
		p[v]=(point){x,y};
		if(!dfs(v))return false;
	}
	return true;
}
int main()
{
	int N;
	scanf("%d",&N);
	for(int T=1;T<=N;++T)
	{
		scanf("%d%d",&n,&m);
		printf("Case #%d: ",T);
		for(int i=1;i<=n;++i)p[i]=(point){1,1};
		memset(head,0,sizeof(head));
		memset(vis,0,sizeof(vis));
		cnt=0;
		for(int i=1;i<=m;++i)
		{
			int u,v,x,y,t;
			scanf("%d%d%d%d",&u,&v,&x,&y);
			if(y<0)
			{
				t=gcd(x,-y);
				addedge(u,v,-(y/t),-(x/t));
				addedge(v,u,x/t,y/t);
			}
			else
			{
				t=gcd(x,y);
				addedge(u,v,y/t,x/t);
				addedge(v,u,x/t,y/t);
			}
		}
		bool flag=false;
		for(int i=1;i<=n;++i)
			if(!vis[i])
			{	
				if(!dfs(i))
				{
					printf("No\n");
					flag=true;
					break;
				}
			}
		if(!flag)printf("Yes\n");
	}
	return 0;
}
